﻿/*
==================================================================
    注意：此文件为Auto代码，不可手动修改【在用绳检测数据】
==================================================================
*/

namespace Services
{
    /// <summary>
    /// Auto在用绳检测数据
    /// </summary>
    public abstract class AutoCheckWireropeDetailDataMapping : BaseMapping<CheckWireropeDetailData, CheckWireropeDetailDataModel, CheckWireropeDetailDataFilterModel>
    {
        public AutoCheckWireropeDetailDataMapping(ICurrentUser currentUser)
            : base(currentUser) { }

        #region 读数据
        /// <summary>
        /// 读数据，从Entity对象转成Model对象
        /// </summary>
        /// <param name="entity">Entity对象</param>
        /// <returns></returns>
        public override CheckWireropeDetailDataModel Entity2Model(CheckWireropeDetailData entity)
        {
            CheckWireropeDetailDataModel model = new CheckWireropeDetailDataModel();

            model.CheckWireropeDetailDataID = entity.CheckWireropeDetailDataID;
            model.GroupInfoID = entity.GroupInfoID;
            model.UsingWireropeID = entity.UsingWireropeID;
            model.CheckWireropeID = entity.CheckWireropeID;
            model.CheckWireropeDetailID = entity.CheckWireropeDetailID;
            model.Type = entity.Type;
            model.Position = entity.Position;
            model.Num = entity.Num;

            return model;
        }
        #endregion

        #region 写数据
        /// <summary>
        /// 写数据，从Model对象转换成Entity对象
        /// </summary>
        /// <param name="model">ViewModel对象</param>
        /// <returns></returns>
        public override CheckWireropeDetailData Model2Entity(CheckWireropeDetailDataModel model)
        {
            CheckWireropeDetailData entity = new CheckWireropeDetailData();

            entity.CheckWireropeDetailDataID = model.CheckWireropeDetailDataID;
            entity.GroupInfoID = model.GroupInfoID;
            entity.UsingWireropeID = model.UsingWireropeID;
            entity.CheckWireropeID = model.CheckWireropeID;
            entity.CheckWireropeDetailID = model.CheckWireropeDetailID;
            entity.Type = model.Type;
            entity.Position = model.Position;
            entity.Num = model.Num;

            return entity;
        }
        #endregion

        #region 搜索条件转换
        /// <summary>
        /// 搜索条件转换，从FilterModel对象转换成Where对象
        /// </summary>
        /// <param name="filterModel">FilterModel对象</param>
        /// <returns></returns>
        public override Expressionable<CheckWireropeDetailData> FilterModel2Where(CheckWireropeDetailDataFilterModel filterModel)
        {
            var where = base.FilterModel2Where(filterModel);

            //编号
            if (filterModel._CheckWireropeDetailDataID.HasValue)
            {
                where = where.And(x => x.CheckWireropeDetailDataID == filterModel._CheckWireropeDetailDataID.Value);
            }
            if (filterModel._CheckWireropeDetailDataIDs.IsNotEmpty() && filterModel._CheckWireropeDetailDataIDs.Count > 0)
            {
                where = where.And(x => filterModel._CheckWireropeDetailDataIDs.Contains(x.CheckWireropeDetailDataID));
            }
            if (filterModel._NotCheckWireropeDetailDataIDs.IsNotEmpty() && filterModel._NotCheckWireropeDetailDataIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotCheckWireropeDetailDataIDs.Contains(x.CheckWireropeDetailDataID));
            }

            //集团
            if (filterModel._GroupInfoID.HasValue)
            {
                where = where.And(x => x.GroupInfoID == filterModel._GroupInfoID.Value);
            }
            if (filterModel._GroupInfoIDs.IsNotEmpty() && filterModel._GroupInfoIDs.Count > 0)
            {
                where = where.And(x => filterModel._GroupInfoIDs.Contains(x.GroupInfoID));
            }
            if (filterModel._NotGroupInfoIDs.IsNotEmpty() && filterModel._NotGroupInfoIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotGroupInfoIDs.Contains(x.GroupInfoID));
            }

            //在用绳
            if (filterModel._UsingWireropeID.HasValue)
            {
                where = where.And(x => x.UsingWireropeID == filterModel._UsingWireropeID.Value);
            }
            if (filterModel._UsingWireropeIDs.IsNotEmpty() && filterModel._UsingWireropeIDs.Count > 0)
            {
                where = where.And(x => filterModel._UsingWireropeIDs.Contains(x.UsingWireropeID));
            }
            if (filterModel._NotUsingWireropeIDs.IsNotEmpty() && filterModel._NotUsingWireropeIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotUsingWireropeIDs.Contains(x.UsingWireropeID));
            }

            //检测基本信息
            if (filterModel._CheckWireropeID.HasValue)
            {
                where = where.And(x => x.CheckWireropeID == filterModel._CheckWireropeID.Value);
            }
            if (filterModel._CheckWireropeIDs.IsNotEmpty() && filterModel._CheckWireropeIDs.Count > 0)
            {
                where = where.And(x => filterModel._CheckWireropeIDs.Contains(x.CheckWireropeID));
            }
            if (filterModel._NotCheckWireropeIDs.IsNotEmpty() && filterModel._NotCheckWireropeIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotCheckWireropeIDs.Contains(x.CheckWireropeID));
            }

            //检测基本信息详情
            if (filterModel._CheckWireropeDetailID.HasValue)
            {
                where = where.And(x => x.CheckWireropeDetailID == filterModel._CheckWireropeDetailID.Value);
            }
            if (filterModel._CheckWireropeDetailIDs.IsNotEmpty() && filterModel._CheckWireropeDetailIDs.Count > 0)
            {
                where = where.And(x => filterModel._CheckWireropeDetailIDs.Contains(x.CheckWireropeDetailID));
            }
            if (filterModel._NotCheckWireropeDetailIDs.IsNotEmpty() && filterModel._NotCheckWireropeDetailIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotCheckWireropeDetailIDs.Contains(x.CheckWireropeDetailID));
            }

            //类型
            if (filterModel._Type.HasValue)
            {
                where = where.And(x => x.Type == filterModel._Type.Value);
            }
            if (filterModel._Types.IsNotEmpty() && filterModel._Types.Count > 0)
            {
                where = where.And(x => filterModel._Types.Contains(x.Type));
            }
            if (filterModel._NotTypes.IsNotEmpty() && filterModel._NotTypes.Count > 0)
            {
                where = where.And(x => !filterModel._NotTypes.Contains(x.Type));
            }

            return where;
        }
        #endregion
    }
}

